package com.kakavr.game.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.math.NumberUtils;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.kakavr.base.service.BaseService;
import com.kakavr.game.dao.IGameBasicDao;
import com.kakavr.page.Pagination;
import com.kakavr.page.constant.PaginationConstant;

@Service
public class GameBasicService extends BaseService implements IGameBasicService {
	@Resource
	private IGameBasicDao gameBasicDao;

	@Override
	public void addGameBasic(Map<String, Object> map) {
		map.put("createtime", DateTime.now().toDate());
		gameBasicDao.addGameBasic(map);
	}

	@Override
	public void updateGameBasic(Map<String, Object> map) {
		gameBasicDao.updateGameBasic(map);
	}

	@Override
	public Pagination<Map<String, Object>> selectGameBasicByPage(
			Map<String, Object> map) {
		PageHelper.startPage(NumberUtils.toInt((String) map
				.get(PaginationConstant.PAGE_NO_NAME)), NumberUtils
				.toInt((String) map.get(PaginationConstant.PAGE_SIZE_NAME)));
		return new Pagination<Map<String, Object>>(
				gameBasicDao.selectGameBasicByPage(map));
	}

	@Override
	public List<Map<String, Object>> selectNewGameList(Map<String, Object> map) {
		map.put("numValue", 8);
		map.put("gameCount", 8);
		return gameBasicDao.selectGameBasicByPage(map);
	}

	@Override
	public Map<String, Object> selectGameInfo(Map<String, Object> map) {
		return gameBasicDao.selectGameInfo(map);
	}

}
